package com.yike.order.controller.feign;

import com.yike.common.base.BaseController;
import com.yike.order.api.param.ShopDataStatisticsFeignParam;
import com.yike.order.api.service.OrderFeignService;
import com.yike.order.api.vo.ShopDataStatisticsFeignVo;
import com.yike.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.math.BigDecimal;

@RestController
@RequestMapping("/feign/order")
@ApiIgnore // 暂时不显示到文档
public class OrderFeignController extends BaseController {

    @Autowired
    private OrderMapper orderMapper;

    @PostMapping("/getShopDataStatistics")
    public ShopDataStatisticsFeignVo getShopDataStatistics(@RequestBody ShopDataStatisticsFeignParam shopDataStatisticsFeignParam) {
        BigDecimal shopRevenue = orderMapper.getShopRevenue(shopDataStatisticsFeignParam.getShopId(),
                shopDataStatisticsFeignParam.getCertainDate(), shopDataStatisticsFeignParam.getBeginTime(),
                shopDataStatisticsFeignParam.getEndTime());
        BigDecimal shopGarrisonRevenue = orderMapper.getShopGarrisonRevenue(shopDataStatisticsFeignParam.getShopId(),
                shopDataStatisticsFeignParam.getCertainDate(), shopDataStatisticsFeignParam.getBeginTime(),
                shopDataStatisticsFeignParam.getEndTime());
        Integer shopOrderNumber = orderMapper.getShopOrderNumber(shopDataStatisticsFeignParam.getShopId(),
                shopDataStatisticsFeignParam.getCertainDate(), shopDataStatisticsFeignParam.getBeginTime(),
                shopDataStatisticsFeignParam.getEndTime());
        Integer shopRefundNumber = orderMapper.getShopRefundNumber(shopDataStatisticsFeignParam.getShopId(),
                shopDataStatisticsFeignParam.getCertainDate(), shopDataStatisticsFeignParam.getBeginTime(),
                shopDataStatisticsFeignParam.getEndTime());

        ShopDataStatisticsFeignVo shopDataStatisticsFeignVo = new ShopDataStatisticsFeignVo();
        shopDataStatisticsFeignVo.setRevenue(shopRevenue);
        shopDataStatisticsFeignVo.setGarrisonRevenue(shopGarrisonRevenue);
        shopDataStatisticsFeignVo.setOrderNumber(shopOrderNumber);
        shopDataStatisticsFeignVo.setRefundNumber(shopRefundNumber);

        return shopDataStatisticsFeignVo;
    }
}

